var jq = jQuery.noConflict();

jQuery(document).ready(function() {
    $(function () {
        getNews();
        proCategoryList()
        product();
        $("#tou").load("Header.html");
    });

    //获取右边的新闻
    function getNews(){
        $.getJSON("easybuy/getnewslist",function (data){
            $.each(data,function (index) {
                var news = data[index];
                $("#newsList").append("<li><span>[ 公告"+(index+1)+" ]</span><a href='Member_Cash.html?id="+news.id+"'>"+news.title+"</a></li>")
            })
        })
    }

    //左侧分类加载
    function proCategoryList(){
            $.ajax({
                url:"easybuy/procategorylistbytype",
                success:function(data){
                    var categorys1 = data[0];
                    var categorys2 = data[1];
                    var categorys3 = data[2];

                    $("#allpro").empty();
                    //一级分类
                    $.each(categorys1,function(index1,category1){
                        $("#allpro").append("<li>\n" +
                            "                    \t<div class=\"fj\">\n" +
                            "                        \t<span class=\"n_img\"><span></span><img src=\"images/nav"+(index1+1)+".png\" /></span>\n" +
                            "                            <span class=\"fl\">"+category1.name+"</span>\n" +
                            "                        </div>\n" +
                            "                        <div class=\"zj\" >\n" +
                            "                            <div class=\"zj_l\">\n" +


                            "                            </div>\n" +
                            "                            <div class=\"zj_r\">\n" +
                            "                                <a href=\"#\"><img src=\"images/n_img1.jpg\" width=\"236\" height=\"200\" /></a>\n" +
                            "                                <a href=\"#\"><img src=\"images/n_img2.jpg\" width=\"236\" height=\"200\" /></a>\n" +
                            "                            </div>\n" +
                            "                        </div>\n");
                        //二级分类
                        $.each(categorys2,function(index2,category2){
                            var parentId = category1.id;
                            if(parentId==category2.parentid){
                                $("#allpro").find('li').eq(index1).children(".zj").children(".zj_l").append("" +
                                    "									<div class=\"zj_l_c\">\n" +
                                    "                                            <h2 class = 'news123'>"+category2.name+"</h2>\n" +
                                    "                                    </div>");

                                //三级分类
                                $.each(categorys3,function(index3,category3){
                                    var parentId2 = category2.id;
                                    if(parentId2==category3.parentid){
                                        $("#allpro").find('li').eq(index1).children(".zj").children(".zj_l").children(".zj_l_c")
                                            .append("<a href=\"#\">"+category3.name+"</a>|")
                                    }


                                    $("#allpro>li").hover(function(){
                                        $(this).find(".fj").addClass("nuw");
                                        $(this).find(".zj").show();
                                    },function(){
                                        $(this).find(".fj").removeClass("nuw");
                                        $(this).find(".zj").hide();
                                    });
                                })
                            }
                        })
                    });
                },
                dataType:"json"
            });
        }

    //详情商品加载
    function product(){
        $.ajax({
            url: "easybuy/procategorylistbytype",
            success:function (data) {
                var categorys1 = data[0];
                var categorys2 = data[1];
                var products=  data[3];
                $("#content").empty();
                $.each(categorys1,function (index1,category1) {

                        //一级头
                        $("#content").append("<div class=\"i_t mar_10\">\n" +
                            "    \t<span class=\"floor_num\">"+(index1+1)+"F</span>\n" +
                            "    \t<span class=\"fl\">"+category1.name+"</span>                \n" +
                            "        \n" +
                            "    </div>\n" +
                            "    <div class=\"content\">\n" +
                            "    \t<div class=\"fresh_left\">\n" +
                            "        \t<div class=\"fre_ban\">\n" +
                            "            \t<div id=\"imgPlay1\">\n" +
                            "                    <ul class=\"imgs\" id=\"actor"+(index1+1)+"\">\n" +
                            "                        <li><a href=\"#\"><img src=\"images/fre_r.jpg\" width=\"211\" height=\"286\" /></a></li>\n" +
                            "                        <li><a href=\"#\"><img src=\"images/fre_r.jpg\" width=\"211\" height=\"286\" /></a></li>\n" +
                            "                        <li><a href=\"#\"><img src=\"images/fre_r.jpg\" width=\"211\" height=\"286\" /></a></li>\n" +
                            "                    </ul>\n" +
                            "                    <div class=\"prevf\">上一张</div>\n" +
                            "                    <div class=\"nextf\">下一张</div> \n" +
                            "                </div>   \n" +
                            "            </div>\n" +
                            "            <div class=\"fresh_txt\">\n" +
                            "            \t<div class=\"fresh_txt_c\">\n" +
                            "                \t\n" +
                            "                </div>\n" +
                            "            </div>\n" +
                            "        </div>\n" +
                            "        <div class=\"fresh_mid\">\n" +
                            "        \t<ul id='sanji'></ul>\n" +
                            "        </div>\n" +
                            "        <div class=\"fresh_right\">\n" +
                            "        \t<ul>\n" +
                            "            \t<li><a href=\"#\"><img src=\"images/fre_b1.jpg\" width=\"260\" height=\"220\" /></a></li>\n" +
                            "                <li><a href=\"#\"><img src=\"images/fre_b2.jpg\" width=\"260\" height=\"220\" /></a></li>\n" +
                            "            </ul>\n" +
                            "        </div>\n" +
                            "    </div>");
                        //二级分类
                        $.each(categorys2,function (index2,category2) {
                            var parentId = category1.id;
                            if(parentId==category2.parentid){
                                $("#content").find(".content").eq(index1).find(".fresh_txt_c")
                                    .append("<a href=\"BrandList.html?id="+category2.id+"\">"+category2.name+"</a>");
                            }
                        });
                        //所有商品
                        $.each(products,function (index3,product) {
                            var parentId = category1.id;

                            if (parentId==product.categorylevel1id){
                                $("#content").find(".content").eq(index1).find("#sanji")
                                    .append("<li>\n" +
                                        "                \t<div class=\"name\"><a href=\"Product.html?id="+product.id+"\">"+product.name+"</a></div>\n" +
                                        "                    <div class=\"price\">\n" +
                                        "                    \t<font>￥<span>"+product.price+"</span></font>&nbsp;&nbsp;26R\n" +
                                        "                    </div>\n" +
                                        "                    <div class=\"img\"><a href=\"Product.html?id="+product.id+"\"><img src=\"http://47.104.137.246:9999/files/"+product.filename+"\" width=\"185\" height=\"155\" /></a></div>\n" +
                                        "                </li>");
                            }
                        });

                        /*$.each(categorys3,function (index3,category3) {
                            $("#sanji").append("<li>\n" +
                                "                \t<div class=\"name\"><a href=\"#\">新鲜美味  进口美食</a></div>\n" +
                                "                    <div class=\"price\">\n" +
                                "                    \t<font>￥<span>198.00</span></font> &nbsp; 26R\n" +
                                "                    </div>\n" +
                                "                    <div class=\"img\"><a href=\"#\"><img src=\"images/fre_1.jpg\" width=\"185\" height=\"155\" /></a></div>\n" +
                                "                </li>");
                        });*/
                    });


            }
        })
    }
});